﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using AdvancedStandingAndScholarship.ASASService;


namespace AdvancedStandingAndScholarship.Views
{
    public partial class RegisterPage : Page
    {
        public RegisterPage()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void btnBack_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // TODO: Add event handler implementation here.
            NavigationService.GoBack();
        }

        private void btnSubmit_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            // MessageBox.Show("asjfklsdf");

            // string email = tbxEmail.Text;
            // string name = tbxName.Text;
            //// string user_type = tbxName.Text; //dummy data only, idk how to do selected index
            // string password = tbxRePassword.Text;

            // ASASService.ASASServiceClient client = new ASASService.ASASServiceClient();
            // client.addNewUserAsync(email, name, password);
            // client.addNewUserCompleted +=new EventHandler<addNewUserCompletedEventArgs>(client_addNewUserCompleted);



        }

        void client_addNewUserCompleted(object sender, addNewUserCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                int result = e.Result;
                MessageBox.Show("Register Sucessful!");

            }
        }

        private void btnSubmitManualAdd_Click(object sender, RoutedEventArgs e)
        {


            string email = tbxEmail.Text;
            string name = tbxName.Text;
            // string user_type = tbxName.Text; //dummy data only, idk how to do selected index
            string user_type = "";
            string password = tbxRePassword.Password;

            if (rbnStaff.IsChecked == true)
            {
                user_type = "Staff";
            }
            else if (rbnAdmin.IsChecked == true)
            {
                user_type = "Admin";
            }

            string pw = tbxPassword.Password;
            string repw = tbxRePassword.Password;

            if (pw != repw)
            {
                MessageBox.Show("Please re-enter password values");
            }
            else
            {
                ASASService.ASASServiceClient client = new ASASService.ASASServiceClient();


                client.addNewUserAsync(email, name, user_type, password, user_type);
                client.addNewUserCompleted += new EventHandler<addNewUserCompletedEventArgs>(client_addNewUserCompleted);
            }





        }


    }
}
